package com.example.demo.observer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoPublisher {

    @Autowired
    ApplicationContext applicationContext;

    @GetMapping("/publish")
    public String publish(String msg){
        ApplicationEvent demoEvent = new DemoEvent(this, msg);
        //发布事件
        applicationContext.publishEvent(demoEvent);
        return msg;
    }
}
